using FineCollection.Intf;

using NUnit.Framework;




namespace FineCollection.Immutable
{
    [TestFixture]
    public class imc_test
    {

        [Test]
        public void Test_Union_Basic_1()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(1111,2222,4444);
            ImmSortSet<long> set2 = new ImmSortSet<long>(2222,3333,5555);

            RRandomSet<long> set3 = imc.Union(set1, set2);

            Assert.AreEqual(5, set3.Count);

            Assert.AreEqual(1111, set3[1]);
            Assert.AreEqual(2222, set3[2]);
            Assert.AreEqual(3333, set3[3]);
            Assert.AreEqual(4444, set3[4]);
            Assert.AreEqual(5555, set3[5]);
        }


        [Test]
        public void Test_Union_OneSetContainsAnotherOne()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(1111,2222,3333,4444);
            ImmSortSet<long> set2 = new ImmSortSet<long>(2222,3333);

            RRandomSet<long> set3 = imc.Union(set1, set2);
            Assert.AreSame(set1, set3);

            RRandomSet<long> set4 = imc.Union(set2, set1);
            Assert.AreSame(set1, set4);
        }


        [Test]
        public void Test_Intersect_NestedLoops_Basic()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(33, 100, 333);
            ImmSortSet<long> set2 = new ImmSortSet<long>(new long[] {11,22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777,888,999});

            RRandomSet<long> set3 = imc.Intersect(set1, set2);

            Assert.AreEqual(2, set3.Count);

            Assert.AreEqual(33,  set3[1]);
            Assert.AreEqual(333, set3[2]);
        }


        [Test]
        public void Test_Intersect_NestedLoops_Reverted()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(new long[] {11,22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777,888,999});
            ImmSortSet<long> set2 = new ImmSortSet<long>(33, 100, 333);

            RRandomSet<long> set3 = imc.Intersect(set1, set2);

            Assert.AreEqual(2, set3.Count);

            Assert.AreEqual(33,  set3[1]);
            Assert.AreEqual(333, set3[2]);
        }


        [Test]
        public void Test_Intersect_NestedLoops_OneInAnother()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(77,777);
            ImmSortSet<long> set2 = new ImmSortSet<long>(new long[] {11,22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777,888,999});

            RRandomSet<long> set3 = imc.Intersect(set1, set2);

            Assert.AreSame(set1, set3);
        }


        [Test]
        public void Test_Intersect_NestedLoops_127_28()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(new long[] {11,22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777});
            ImmSortSet<long> set2 = new ImmSortSet<long>(22, 888);

            RRandomSet<long> set3 = imc.Intersect(set1, set2);

            Assert.AreEqual(1, set3.Count);

            Assert.AreEqual(22, set3[1]);
        }


        [Test]
        public void Test_Intersect_NestedLoops_2379_17()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(new long[] {22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777,888,999});
            ImmSortSet<long> set2 = new ImmSortSet<long>(11, 777);

            RRandomSet<long> set3 = imc.Intersect(set1, set2);

            Assert.AreEqual(1, set3.Count);

            Assert.AreEqual(777, set3[1]);
        }


        [Test]
        public void Test_Intersect_NestedLoops_OneLowerAnother()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(3,7);
            ImmSortSet<long> set2 = new ImmSortSet<long>(new long[] {11,22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777,888,999});

            RRandomSet<long> set3 = imc.Intersect(set1, set2);

            Assert.IsTrue(set3.IsEmpty);
            Assert.AreSame(ImmOrderZero<long>.zero, set3);
        }


        [Test]
        public void Test_Intersect_NestedLoops_OneAfterAnother()
        {
            ImmSortSet<long> set1 = new ImmSortSet<long>(777777,7777777);
            ImmSortSet<long> set2 = new ImmSortSet<long>(new long[] {11,22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777,888,999});

            RRandomSet<long> set3 = imc.Intersect(set1, set2);

            Assert.IsTrue(set3.IsEmpty);
            Assert.AreSame(ImmOrderZero<long>.zero, set3);
        }


    }
}